#include "head.hpp"
int init_pool(son_t *list, int num)
{
    for (int i = 0; i < num; i++)
    {
        int local_socket[2];
        socketpair(AF_LOCAL, SOCK_STREAM, 0, local_socket);
        pid_t pid = fork();
        if (pid == 0)
        {
            setpgid(0, 0);
            close(local_socket[0]);
            son_main(local_socket[1]);
        }
        else
        {
            close(local_socket[1]);
            list[i].local_socket = local_socket[0];
            list[i].pid = pid;
            list[i].status = FREE;
        }
    }
    return 0;
}
int to_son(son_t *list, int num, int net_fd)
{
    for (int i = 0; i < num; i++)
    {
        if (list[i].status == FREE)
        {
            local_send(list[i].local_socket, net_fd, 0);
            list[i].status = BUSY;
            break;
        }
    }
    return 0;
}